Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

trek-router

Package Overview
Dependencies
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

trek-router

A fast HTTP router

  • 0.1.9
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.6K
increased by1140.63%
Maintainers
1
Weekly downloads
 
Created
Source

trek-router

A fast HTTP router, inspired by Echo's Router.

NPM version Build status Test coverage License Dependency status

Benchmarks

See benchmarks, use GitHub API Routes and Discourse API Routes.

VS

$ npm run benchmark

GitHub API, 203 routes:
trek-router x 5,095 ops/sec ±2.26% (98 runs sampled)
memoryUsage: { rss: 42135552, heapTotal: 32478208, heapUsed: 18689464 }
path-to-regexp x 408 ops/sec ±1.58% (93 runs sampled)
memoryUsage: { rss: 60882944, heapTotal: 51053056, heapUsed: 16037648 }
route-recognizer x 323 ops/sec ±1.27% (90 runs sampled)
memoryUsage: { rss: 63623168, heapTotal: 54136832, heapUsed: 28968984 }
route-trie x 1,229 ops/sec ±1.12% (95 runs sampled)
memoryUsage: { rss: 65597440, heapTotal: 55168768, heapUsed: 27494288 }
routington x 1,201 ops/sec ±0.30% (98 runs sampled)
memoryUsage: { rss: 68001792, heapTotal: 59284480, heapUsed: 28473048 }
Fastest is trek-router

Discourse API, 359 routes:
trek-router x 3,801 ops/sec ±0.09% (101 runs sampled)
memoryUsage: { rss: 70402048, heapTotal: 61348352, heapUsed: 30221032 }
path-to-regexp x 59.41 ops/sec ±0.23% (78 runs sampled)
memoryUsage: { rss: 72286208, heapTotal: 63400192, heapUsed: 28175392 }
route-recognizer x 211 ops/sec ±1.14% (92 runs sampled)
memoryUsage: { rss: 75005952, heapTotal: 64432128, heapUsed: 21000584 }
route-trie x 1,131 ops/sec ±0.85% (97 runs sampled)
memoryUsage: { rss: 74936320, heapTotal: 64432128, heapUsed: 18404472 }
routington x 1,076 ops/sec ±0.45% (100 runs sampled)
memoryUsage: { rss: 74973184, heapTotal: 64432128, heapUsed: 25122008 }
Fastest is trek-router

Usage

import Router from 'trek-router';

let r = new Router();
// static route
r.add('GET', '/folders/files/bolt.gif', () => {});
// param route
r.add('GET', '/users/:id', () => {});
// catch-all route
r.add('GET', '/books/*', () => {});

let result = r.find('GET', '/users/233')
// => [handler, params]
// => [()=>{}, [{name: id, value: 233}]]

// Not Found
let result = r.find('GET', '/photos/233')
// => [handler, params]
// => [undefined, []]

License

MIT

Keywords

FAQs

Package last updated on 22 Apr 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc